package org.jeecg.modules.kuybFacilitator.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.jeecg.modules.kuybFacilitator.entity.KuybFacilitator;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;

import java.math.BigDecimal;
import java.util.List;

/**
 * @Description: kuyb_facilitator
 * @Author: jeecg-boot
 * @Date:   2021-09-22
 * @Version: V1.0
 */
public interface KuybFacilitatorMapper extends BaseMapper<KuybFacilitator> {

    @Select("SELECT *,\n" +
            "ROUND(6378.138 * 2 * ASIN(SQRT(POW(SIN((${latitudes} * PI() / 180 - latitudes * PI() / 180) / 2),2) + COS(${latitudes} * PI() / 180) * COS(latitudes * PI() / 180) * POW(\n" +
            "SIN((${longitudes} * PI() / 180 - longitudes * PI() / 180) / 2),2))) * 1000) AS distance\n" +
            "FROM kuyb_facilitator where type=${type} ORDER BY distance limit ${(pageNo-1)*pageSize},${pageSize}")
    List<KuybFacilitator> findTopFacilitatorByType(@Param("pageNo") int pageNo, @Param("pageSize") int pageSize, @Param("type") String type, @Param("latitudes")BigDecimal latitudes,@Param("longitudes") BigDecimal longitudes);
}
